package com.bdqn.gulimall.product.config;


import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;
import java.net.InetAddress;

/**
 * redis分布式锁配置类
 */
@Configuration
public class MyRedissonConfig {

    /**
     * 所有对Redisson的使用都是通过RedissonClient进行操作
     * @return
     * @throws IOException
     */
    @Bean(destroyMethod="shutdown")
    public RedissonClient redisson() throws IOException {
        //解析域名拿到公网IP
        InetAddress[] allByName = InetAddress.getAllByName("www.madagaga.top");
        System.out.println();
        //配置地址，并且以单节点运行

        Config config = new Config();
        config.useSingleServer().setAddress("redis://"+allByName[0].getHostAddress()+":26379");
        //返回Config创建出RedissonClient实例
        return Redisson.create(config);
    }

}
